#include "KMeansNeuron.h"

#include "../Math/KernelFunction/GaussKernelFunction.h"

CKMeansNeuron::CKMeansNeuron(int inputDimension, double variance) :
	m_CenterPosition(inputDimension),
	m_NJ(0)
{
	this->m_KernelFunction = std::make_shared<CGaussKernelFunction>(variance);
	this->m_KernelFunction->SetKernelVector(this->m_CenterPosition);
}

double CKMeansNeuron::Execute(const Vector & inputPosition)
{
	return this->m_KernelFunction->Do(inputPosition);
}

double CKMeansNeuron::Norm(const Vector & testPoint)
{
	return this->m_CenterPosition.NormSquare(testPoint);
}

Vector CKMeansNeuron::GetMeansPosition()
{
	return this->m_CenterPosition;
}

void CKMeansNeuron::InsertMeansPosition(const Vector & centerPosition)
{
	this->m_CenterPosition = this->m_CenterPosition * (double)this->m_NJ;
	this->m_CenterPosition = this->m_CenterPosition + centerPosition;
	this->m_CenterPosition = this->m_CenterPosition * (1.0 / (++this->m_NJ));
	
	this->m_KernelFunction->SetKernelVector(this->m_CenterPosition);
}

shared_ptr<IKernelFunctionBase> CKMeansNeuron::GetKernelFunctionObject()
{
	return this->m_KernelFunction;
}

void CKMeansNeuron::ResetKernelFunctionObject(const shared_ptr<IKernelFunctionBase> & kernelFunc)
{
	this->m_KernelFunction = kernelFunc;
}